
    use std::fs::File;
    use std::io;
    use std::io::{Read, Write};
    use std::net::{TcpListener, TcpStream};
    use std::thread::{sleep, spawn};
    use std::time::Duration;

    // 服务器端（非阻塞写入示例）
    fn main() {
        spawn(move || {
            let mut file = File::open("d:/abc.log").unwrap();
            let mut file_data = vec![];
            file.read_to_end(&mut file_data).unwrap();
            let listener = TcpListener::bind("127.0.0.1:10000").unwrap();
            let (mut stream, _) = listener.accept().unwrap();

            stream.set_nonblocking(true).unwrap();
            for chunk in file_data.chunks(10) {
                loop {
                    match stream.write(chunk) {
                        Ok(n) => break,
                        Err(e) if e.kind() == io::ErrorKind::WouldBlock => {
                            sleep(Duration::from_millis(10)); // 等待缓冲区可用
                            continue;
                        }
                        Err(e) => panic!("Write error: {}", e),
                    }
                }
            }
        });
        sleep(Duration::from_secs(1));
        // 客户端（非阻塞读取示例）
        spawn(move || {
            let mut stream = TcpStream::connect("127.0.0.1:10000").unwrap();
            stream.set_nonblocking(true).unwrap();
            let mut buffer = [0u8; 1024];
            loop {
                match stream.read(&mut buffer) {
                    Ok(0) => break,
                    Ok(n) => println!("Received {} bytes", n),
                    Err(e) if e.kind() == io::ErrorKind::WouldBlock => {
                        sleep(Duration::from_millis(10)); // 等待数据到达
                        continue;
                    }
                    Err(e) => panic!("Read error: {}", e),
                }
            }
        });
        loop {

        }
    }


